public class HttpWebResponseUtility
{
	public HttpWebResponseUtility()
	{
	}

private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; 

    public static HttpWebResponse CreatePostHttpResponse(string url,String parameters, int? timeout, string userAgent, Encoding requestEncoding, CookieCollection cookies) {
        if (string.IsNullOrEmpty(url)) {
            throw new ArgumentNullException("url");  
        }
        if (requestEncoding == null) {
            throw new ArgumentNullException("requestEncoding");  
        }
        HttpWebRequest request = null;
        //如果是发送HTTPS请求 
        if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
        {
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            request = WebRequest.Create(url) as HttpWebRequest;
            request.ProtocolVersion = HttpVersion.Version10;
        }
        else {
            request = WebRequest.Create(url) as HttpWebRequest;        
        }
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        if (!string.IsNullOrEmpty(userAgent))
        {
            request.UserAgent = userAgent;
        }
        else {
            request.UserAgent = DefaultUserAgent; 
        }
        if (timeout.HasValue) {

            request.Timeout = timeout.Value; 
        }
        if (cookies != null) {
            request.CookieContainer = new CookieContainer();
            request.CookieContainer.Add(cookies);  
        }
        //如果需要POST数据
        if (parameters != null) {
            byte[] data = requestEncoding.GetBytes(parameters);
            using (Stream stream = request.GetRequestStream()) {
                stream.Write(data, 0, data.Length);  
            }
        }
        return request.GetResponse() as HttpWebResponse;
        
    }

    private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) {
        return true; //总是接受   
}
}